//
//  XSMainViewController.swift
//  微博项目
//
//  Created by XISHAN on 16/3/2.
//  Copyright © 2016年 XISHAN. All rights reserved.
//

import UIKit

class XSMainViewController: UITabBarController {

    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = XSTabBar()
        
        tabBar.composeCallBack = {[weak self] in
            print("弹出Compose窗口")
            let composeView = XSComposeView()
            composeView.show(self!)
        }
        
        setValue(tabBar, forKeyPath: "tabBar")
        
        addChildViewController(XSHomeViewController(), imageNamed: "tabbar_home", title: "主页")
        addChildViewController(XSMessageViewController(), imageNamed: "tabbar_message_center", title: "消息")
        addChildViewController(XSDiscoveryViewController(), imageNamed: "tabbar_discover", title: "发现")
        addChildViewController(XSProfileViewController(), imageNamed: "tabbar_home", title: "Me")
        

        // Do any additional setup after loading the view.
    }

    //添加子控制器
    
    private func addChildViewController(childController: UIViewController,imageNamed: String,title: String) {
        
        childController.tabBarItem.title = title
        childController.navigationItem.title = title
        
        //设置普通样式下的图片
        childController.tabBarItem.image = UIImage(named: imageNamed)
        //渲染方式设为原样
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageNamed)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置字体颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        
        //设置tabBarItem的字体属性
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(10)], forState: UIControlState.Normal)
        //在TabBar上添加子控制器,相当于OC中的
//   [[UINavigationController alloc]initWithRootViewController:childController]
        addChildViewController(XSNavigationViewController(rootViewController:childController))
    }
    

   

}
